//
//  ColorView.m
//  Picture
//
//  Created by 孙玉琢 on 16/11/23.
//  Copyright © 2016年 孙玉琢. All rights reserved.
//

#import "ColorView.h"
// 屏幕高度
#define HEIGHT [UIScreen mainScreen].bounds.size.height
// 屏幕宽度
#define WIDTH [UIScreen mainScreen].bounds.size.width

@implementation ColorView

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        
        self.colorScroll.delegate = self;
        self.colorScroll.dataSource = self;
        [self loadColors];
    }
    return self;
}
//颜色
-(void)loadColors{
    
    //set up colors
    self.colors = [NSArray array];
    self.colors = @[@"000000",@"FFFFFF",@"F54437",@"E91F63",@"9B29B0",@"663CB7",@"3F52B4",@"2198F2",@"03AAF4",@"01BCD4",@"019787",@"F6E1C3",@"8AC349",@"CCDC38",@"FDEB3A",@"FDC106",@"FE9900",@"FD5720",@"775545",@"9D9D9D",@"5F7C8A"];
    
    //configure swipe view
    _colorScroll.alignment = SwipeViewAlignmentEdge;
    _colorScroll.pagingEnabled = NO;
    _colorScroll.wrapEnabled = NO;
    _colorScroll.itemsPerPage = 3;
    _colorScroll.truncateFinalPage = NO;
}

- (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView
{
    return [self.colors count];
}

- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    UILabel *label = (UILabel *)view;
    
    //create or reuse view
    if (view == nil)
    {
        label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, WIDTH/7, WIDTH/7)];
        
        label.textColor = [UIColor whiteColor];
        view = label;
    }
    
    label.backgroundColor = [UIColor hexStringToColor:[self.colors objectAtIndex:index]];
    //return view
    return view;
}

- (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index
{
    _colorString = [self.colors objectAtIndex:index];
    [self.delegate getColorString:_colorString];
}

- (IBAction)sliderClick:(UISlider *)sender {
    
    [self.delegate getAlphaValue:self.stickerViewID alpha:sender.value];
}

- (IBAction)removeCurrentView:(UIButton *)sender {
    
    [self.delegate deletCurrentView:self.stickerViewID];
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
